package com.info.zhiduoduo.common.excelconverter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.info.zhiduoduo.common.constants.invoice.InvoiceType;
import com.info.zhiduoduo.common.utils.StringUtil;

/**
 * 发票类型： 1普票 2专票
 */
public class InvoiceTypeConverter implements Converter<Integer> {

	@Override
	public Class supportJavaTypeKey() {
		return null;
	}

	@Override
	public CellDataTypeEnum supportExcelTypeKey() {
		return null;
	}

	@Override
	public Integer convertToJavaData(CellData cellData, ExcelContentProperty excelContentProperty,
	                                 com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
		String value = cellData.getStringValue();
		if (StringUtil.equals(value, "普票")) return InvoiceType.GENERAL;
		if (StringUtil.equals(value, "专票")) return InvoiceType.SPECIAL;
		return InvoiceType.GENERAL;
	}

	@Override
	public CellData convertToExcelData(Integer integer, ExcelContentProperty excelContentProperty,
	                                   com.alibaba.excel.metadata.GlobalConfiguration globalConfiguration) throws Exception {
		if (integer == null) {
			return new CellData("");
		} else if (integer == InvoiceType.GENERAL) {
			return new CellData("普票");
		} else if (integer == InvoiceType.SPECIAL) {
			return new CellData("专票");
		} else {
			return new CellData("");
		}
	}
}
